import { ElMessage, ElMessageBox as MessageBox } from 'element-plus'

const success  = (msg:string='保存成功')=>{
    ElMessage({
        message: msg,
        type: 'success',
    })
}

const error = (msg:string)=>{
    ElMessage({            
        message: msg,
        type: 'error',
    })
}

/**
 * 删除确认
 */
const delConfirm = ()=>{

    return new Promise((resolve,reject)=>{

        MessageBox.confirm('确定要删除吗?','提示',
            {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            }
          ).then(() => {
            resolve("");
          })
          .catch(() => {
            reject();
            ElMessage({
              type: 'info',
              message: '已取消删除',
            })
          })
    });

   
}

const saveConfirm = (message:string)=>{

  return new Promise((resolve,reject)=>{

      MessageBox.confirm(message,'提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          }
        ).then(() => {
          resolve("");
        })
        .catch(() => {
          reject();
          ElMessage({
            type: 'info',
            message: '已取消',
          })
        })
  });

 
}

export default {
    success,delConfirm,error,saveConfirm
}